﻿using Bomber.TF.Common.GDI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bomber.TF.GameCenter
{
    public unsafe abstract class GameBase : IDisposable, ICloneable
    {
        private Size _size;
        private readonly SpeciesType _speciesType;
        private readonly int _height;
        private readonly int _width;
        public GameBase(SpeciesType speciesType, Size size)
        {
            _size = size;
            _height = size.Height;
            _width = size.Width;
            _speciesType = speciesType;
        }
        public SpeciesType SpeciesType { get { return _speciesType; } }
        public Size Size { get { return _size; } set { _size = value; } }
        public Point Location { get; set; }
        public int Row { get; set; }
        public int Column { get; set; }
        public int MaxRow { get; set; }
        public int MaxColumn { get; set; }
        public int StartX { get; set; }
        public int StartY { get; set; }
        public int CellWidth { get; set; }
        public int CellHeight { get; set; }
        public float ZoomX { get; set; }
        public float ZoomY { get; set; }
        public void CopyCoordinate(GameBase gameBase)
        {
            gameBase.Row = Row;
            gameBase.Column = Column;
            gameBase.CellWidth = CellWidth;
            gameBase.CellHeight = CellHeight;
            gameBase.MaxColumn = MaxColumn;
            gameBase.MaxRow = MaxRow;
            gameBase.StartX = StartX;
            gameBase.StartY = StartY;
            gameBase.ZoomX = ZoomX;
            gameBase.ZoomY = ZoomY;
        }
        public Rectangle GetRect()
        {
            return new Rectangle(Location.X, Location.Y, Size.Width, Size.Height);
        }
        public bool IsBlock => this.SpeciesType.IsBlock();
        public bool IsBomber => this.SpeciesType.IsBomber();
        public bool IsBomb => this.SpeciesType.IsBomb();
        public bool IsTool => this.SpeciesType.IsTool();
        public virtual void Business(GameListBase* ptr) { }
        public abstract void Draw(Graphics g);
        public virtual void UpdateLocation()
        {
            this.Location = new Point(StartX + Column * CellWidth, StartY + Row * CellHeight);
        }
        public virtual void SizeChange(int row, int column, int startX, int startY, int cellWidth, int cellHeight, float zoomX, float zoomY)
        {
            ZoomX = zoomX;
            ZoomY = zoomY;
            CellWidth = cellWidth;
            CellHeight = cellHeight;
            MaxColumn = column;
            MaxRow = row;
            StartX = startX;
            StartY = startY;

            UpdateLocation();
            this.Size = new Size((int)(_width * ZoomX), (int)(_height * ZoomY));
        }
        public void Dispose()
        {
            DisposeAll();
        }
        protected virtual void DisposeAll()
        {

        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
